package cn.majun.mapper;

import cn.majun.pojo.Administrator;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.Set;

public interface AdministratorMapper extends BaseMapper<Administrator> {

    @Select("select DISTINCT r.`code` from tb_role as r " +
            "left join tb_admin_role as ar on r.id = ar.role_id " +
            "left join tb_admin as a on a.id = ar.admin_id " +
            "where a.username = #{username}")
    Set<String> findRolesByUsername(String username);

    @Select("select DISTINCT p.`code` from tb_permission as p " +
            "left join tb_role_perm as rp on p.id = rp.perm_id " +
            "left join tb_role as r on rp.role_id = r.id " +
            "left join tb_admin_role ar on r.id = ar.role_id " +
            "left join tb_admin as a on a.id = ar.admin_id " +
            "where a.username = #{username}")
    Set<String> findPermissionsByUsername(String username);
}
